Shader "post/radialBlur"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }

    SubShader{
        CGINCLUDE

        #include "UnityCG.cginc"

        sampler2D _MainTex;
        half4 _MainTex_TexelSize;
        float2 _blurCenter;
        float _blurFactor;
        int _blurNum;

        struct v2f {
            float4 pos : SV_POSITION;
            half2 uv :TEXCOORD0;
        };

        v2f vertRadialBlur(appdata_img v){
            v2f o;
            o.pos = UnityObjectToClipPos(v.vertex);
            o.uv = v.texcoord;

            return o;
        }

        struct v2fVert { 
			float4 pos : SV_POSITION;
			half2 uv: TEXCOORD0;
		};
		
		fixed4 fragRadialBlur(v2fVert i) : SV_Target {
			fixed4 color = fixed4(0,0,0,0);

			for (int j = 1; j <= _blurNum; j++) {
                float2 dir = i.uv - _blurCenter;
                color += tex2D(_MainTex, i.uv + _blurFactor * dir * j);
			}
			
            color /= _blurNum;
			return color;
		}

        ENDCG

        ZTest Always Cull Off ZWrite Off

        Pass{
			CGPROGRAM  
			#pragma vertex vertRadialBlur
			#pragma fragment fragRadialBlur  
			ENDCG  
        }
    }
    FallBack Off
}
